<?php
class Application_Model_StockDate
{
	protected $_dbTable;
	public $_mId;
	public $_mStockId;
	public $_mTicker;
	public $_mStockExchange;
	public $_mDate;
	public $_mTime;
	public $_mPer;
	public $_mOpen;
	public $_mHigh;
	public $_mLow;
	public $_mClose;
	public $_mVolume;
	public $_mOpenint;
	public $_mIsIndex;
	public $_mHsrr;
	public $_mSoNgayTk;
	public $_mRet;

	public function getId(){
		return $this->_mId;
	}
	public function setId($value){
		$this->_mId = $value;
		return $this;
	}
	public function getStockId(){
		return $this->_mStockId;
	}
	public function setStockId($value){
		$this->_mStockId = $value;
		return $this;
	}
	public function getTicker(){
		return $this->_mTicker;
	}
	public function setTicker($value){
		$this->_mTicker = $value;
		return $this;
	}
	public function getStockExchange(){
		return $this->_mStockExchange;
	}
	public function setStockExchange($value){
		$this->_mStockExchange = $value;
		return $this;
	}
	public function getDate(){
		return $this->_mDate;
	}
	public function setDate($value){
		$this->_mDate = $value;
		return $this;
	}
	public function getTime(){
		return $this->_mTime;
	}
	public function setTime($value){
		$this->_mTime = $value;
		return $this;
	}
	public function getPer(){
		return $this->_mPer;
	}
	public function setPer($value){
		$this->_mPer = $value;
		return $this;
	}
	public function getOpen(){
		return $this->_mOpen;
	}
	public function setOpen($value){
		$this->_mOpen = $value;
		return $this;
	}
	public function getHigh(){
		return $this->_mHigh;
	}
	public function setHigh($value){
		$this->_mHigh = $value;
		return $this;
	}
	public function getLow(){
		return $this->_mLow;
	}
	public function setLow($value){
		$this->_mLow = $value;
		return $this;
	}
	public function getClose(){
		return $this->_mClose;
	}
	public function setClose($value){
		$this->_mClose = $value;
		return $this;
	}
	public function getVolume(){
		return $this->_mVolume;
	}
	public function setVolume($value){
		$this->_mVolume = $value;
		return $this;
	}
	public function getOpenint(){
		return $this->_mOpenint;
	}
	public function setOpenint($value){
		$this->_mOpenint = $value;
		return $this;
	}
	public function getIsIndex(){
		return $this->_mIsIndex;
	}
	public function setIsIndex($value){
		$this->_mIsIndex = $value;
		return $this;
	}
	public function getHsrr(){
		return $this->_mHsrr;
	}
	public function setHsrr($value){
		$this->_mHsrr = $value;
		return $this;
	}
	public function getSoNgayTk(){
		return $this->_mSoNgayTk;
	}
	public function setSoNgayTk($value){
		$this->_mSoNgayTk = $value;
		return $this;
	}
	public function getRet(){
		return $this->_mRet;
	}
	public function setRet($value){
		$this->_mRet = $value;
		return $this;
	}


	public function setDbTable($dbTable){
		if (is_string($dbTable))
			$dbTable = new $dbTable();
		if (!$dbTable instanceof Zend_Db_Table_Abstract)
			throw new Exception('Invalid table data gateway provided');
		$this->_dbTable = $dbTable;
		return $this;
	}
	public function getDbTable(){
		if (null === $this->_dbTable)
			$this->setDbTable('Application_Model_DbTable_StockDate');
		return $this->_dbTable;
	}
	public function save(Application_Model_StockDate $old = null){
		$item = $this;
		$data = array();
		if(isset($item->_mId)) $data['id'] = $item->_mId;
		if(isset($item->_mStockId)) $data['stock_id'] = $item->_mStockId;
		if(isset($item->_mTicker)) $data['ticker'] = $item->_mTicker;
		if(isset($item->_mStockExchange)) $data['stock_exchange'] = $item->_mStockExchange;
		if(isset($item->_mDate)) $data['date'] = $item->_mDate;
		if(isset($item->_mTime)) $data['time'] = $item->_mTime;
		if(isset($item->_mPer)) $data['per'] = $item->_mPer;
		if(isset($item->_mOpen)) $data['open'] = $item->_mOpen;
		if(isset($item->_mHigh)) $data['high'] = $item->_mHigh;
		if(isset($item->_mLow)) $data['low'] = $item->_mLow;
		if(isset($item->_mClose)) $data['close'] = $item->_mClose;
		if(isset($item->_mVolume)) $data['volume'] = $item->_mVolume;
		if(isset($item->_mOpenint)) $data['openint'] = $item->_mOpenint;
		if(isset($item->_mIsIndex)) $data['is_index'] = $item->_mIsIndex;
		if(isset($item->_mHsrr)) $data['hsrr'] = $item->_mHsrr;
		if(isset($item->_mSoNgayTk)) $data['so_ngay_tk'] = $item->_mSoNgayTk;
		if(isset($item->_mRet)) $data['ret'] = $item->_mRet;

		if($old === null)
			$this->getDbTable()->insert($data);
		else{
			$key = array();
			$old->_mId === null ? $key[] = 'id is NULL' : $key['id = ?'] =  $old->_mId;

			$this->getDbTable()->update($data, $key);
		}
	}
	public function delete(){
		$item = $this;
		$old = $item;
		$key = array();
			$old->_mId === null ? $key[] = 'id is NULL' : $key['id = ?'] =  $old->_mId;

		$this->getDbTable()->delete($key);
	}
	public function fetchAll($where = null, $order = null, $count = null, $offset = null){
		$resultSet = $this->getDbTable()->fetchAll($where, $order, $count, $offset);
		$entries   = array();
		foreach ($resultSet as $row) {
			$item = new Application_Model_StockDate();
			if(isset($row->id))$item->_mId = $row->id;
			if(isset($row->stock_id))$item->_mStockId = $row->stock_id;
			if(isset($row->ticker))$item->_mTicker = $row->ticker;
			if(isset($row->stock_exchange))$item->_mStockExchange = $row->stock_exchange;
			if(isset($row->date))$item->_mDate = $row->date;
			if(isset($row->time))$item->_mTime = $row->time;
			if(isset($row->per))$item->_mPer = $row->per;
			if(isset($row->open))$item->_mOpen = $row->open;
			if(isset($row->high))$item->_mHigh = $row->high;
			if(isset($row->low))$item->_mLow = $row->low;
			if(isset($row->close))$item->_mClose = $row->close;
			if(isset($row->volume))$item->_mVolume = $row->volume;
			if(isset($row->openint))$item->_mOpenint = $row->openint;
			if(isset($row->is_index))$item->_mIsIndex = $row->is_index;
			if(isset($row->hsrr))$item->_mHsrr = $row->hsrr;
			if(isset($row->so_ngay_tk))$item->_mSoNgayTk = $row->so_ngay_tk;
			if(isset($row->ret))$item->_mRet = $row->ret;

			$entries[] = $item;
		}
		return $entries;
	}
}
